package com.kehao.useful_method;

import org.junit.Test;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class DSHelper {

    // 栈
    @Test
    public void stackTest(){
        Stack stack = new Stack<>();

        System.out.println(stack.empty());
        System.out.println(stack.size());

        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);

        System.out.println(stack.empty());
        System.out.println(stack.size());

        //peek查看栈顶元素不用删除  pop弹出栈顶元素
        System.out.println(stack.peek());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());

        System.out.println(stack.empty());
    }

    // 队列
    @Test
    public void queueTest(){
        //普通队列
        Queue queue = new LinkedList();
        queue.offer(1);//入队列
        queue.offer(2);//入队列
        queue.offer(3);//入队列
        System.out.println(queue.isEmpty());
        System.out.println(queue.peek());//获取队头元素
        System.out.println(queue.poll());//出队列
        System.out.println(queue.poll());//出队列
        System.out.println(queue.poll());//出队列

        //双端队列
        Deque deque = new LinkedList<>();
        deque.isEmpty();//判断空
        deque.peekFirst();//访问队头数据
        deque.peekLast();//访问队尾数据
        deque.addFirst(2);
        deque.addLast(1);//在队尾插入数据
        deque.removeLast();//移除队尾数据
        deque.removeFirst();//移除队头数据

    }
}
